<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/11/15
 * Time: 09:58
 */

namespace app\modules\adapter\controller;

use app\modules\adapter\Book;
use app\modules\adapter\EBook;
use app\modules\adapter\EBookAdapter;
use yii\web\Controller;

class DefaultController extends Controller
{
    /**
     * 适配器模式示例
     * 将一个类的接口转换成可应用的兼容接口。适配器使原本由于接口不兼容而不能一起工作的那些类可以一起工作。
     *
     * @date   2018/11/15
     * @author edmmss
     * @return bool
     */
    public function actionIndex()
    {
        $book = new Book();
        $book->open();

        var_dump($book->getPage());
        $book->turnPage();
        var_dump($book->getPage());

        $eBook = new EBook();
        $adapterBook = new EBookAdapter($eBook);
        $adapterBook->open();

        var_dump($adapterBook->getPage());
        $adapterBook->turnPage();
        var_dump($adapterBook->getPage());

        return true;
    }
}